<template>
  <div class="card">
    <div class="right-info">
      <h2>店铺名称:{{ state.restaurant_name }}</h2>
      <p>店铺地址:{{ state.address }}</p>
      <p>联系电话:{{ state.contact_number }}</p>
      <el-button class="go-back" @click="goBack">返回</el-button>
    </div>
    <el-card class="left-img">
      <img :src="state.image_url" alt="" />
    </el-card>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { restaurantDetailApi } from "@/utils/api";
import { useRouter } from "vue-router";
const router = useRouter();

const id = router.currentRoute.value.params.id;

const state = ref({});

const getDetail = async () => {
  try {
    const res = await restaurantDetailApi({ id });
    const restaurantData = res.data[0];
    console.log(restaurantData);
    restaurantData.image_url = `http://localhost:3000/images/rest/${restaurantData.image_url}`;
    state.value = restaurantData;
  } catch (error) {
    console.error(error);
  }
};

getDetail();

const goBack = () => {
  console.log("go back");

  router.go(-1);
};
</script>

<style lang="less" scoped>
.card {
  display: flex;
  justify-content: space-around;
  align-items: center;
  margin-top: 20px;
}

.left-img {
  width: 600px;
  height: 400px;
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

.right-info {
  margin-left: 20px;
}

.go-back {
  margin-top: 20px;
  background-color: #409eff;
  color: #fff;
  border-radius: 4px;
  padding: 10px 20px;
  font-size: 16px;
  cursor: pointer;
}
</style>
